package com.eatme.leetcode.problems;


public class Solution704V3 {

    public int search(int[] data,int target) {
        int l = 0, r = data.length -1;
        while (l<=r) {
            // 在 data[l,r] 的范围查找 target
            int mid = l + (r-l) /2 ; // 避免整型溢出
            if (data[mid]==target)
                return mid;
            if (data[mid]<target)
                l=mid+1;
            else r = mid-1;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] nums = {-1,0,3,5,9,12};
        int target = 9;
        int ret =new Solution704V3().search(nums,target);
        System.out.println(ret);
    }
}
